<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <h1>测试链接</h1>
  </body>
  <script>
    // 创建连接
    const websocket = new WebSocket("ws://localhost:1760/");
    // 发送信息
    websocket.onopen = function () {
      console.log("我连接上了,并开始发送消息");
      let data = {
        type: "sendTo",
        userId: "user2",
        msg: "给微信发消息",
      };
      setInterval(function () {
        websocket.send(JSON.stringify(data));
      },2000);
    };
    // 接收信息
    websocket.onmessage = function (e) {
      console.log(e.data);
    };
  </script>
</html>
